home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tcclib.exe / GCOMM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-07  |  1.5 KB  |  91 lines

  1. #include <bios.h>
  2. #include <stdio.h>
  3. #include "tcclib.h"
  4.  
  5. #define MAXKEYS 64
  6.  
  7. typedef struct {
  8.     int  Key;
  9.     void (*Func)( void );
  10. } GCommKeyType;
  11.  
  12. GCommKeyType GCommKey[MAXKEYS];
  13.  
  14. void GCommKeyNoOp( void );
  15. void GCommKeyNoOp() {}
  16.  
  17. void (*GCommBackgroundFunc)( void ) = NULL;
  18.  
  19. void GCommBackground( void (*funct)( void ) )
  20. {
  21.     GCommBackgroundFunc = funct;
  22. }
  23.  
  24. void GCommLink ( int key, void (*funct)( void ) )
  25. {
  26.     register int i;
  27.  
  28.     for (i=0; i<MAXKEYS; ++i) {
  29.         if ( key == GCommKey[i].Key ) {
  30.             GCommKey[i].Func = funct;
  31.             return;
  32.         }
  33.     }
  34.     for (i=0; i<MAXKEYS; ++i) {
  35.         if ( GCommKey[i].Key == 0 ) {
  36.             GCommKey[i].Key = key;
  37.             GCommKey[i].Func = funct;
  38.             return;
  39.         }
  40.     }
  41. }
  42.  
  43. void GCommUnlink (int key)
  44. {
  45.     register int i;
  46.  
  47.     for (i=0; i<MAXKEYS; ++i) {
  48.         if ( key == GCommKey[i].Key ) {
  49.             GCommKey[i].Key = 0;
  50.             GCommKey[i].Func = GCommKeyNoOp;
  51.             return;
  52.         }
  53.     }
  54. }
  55.  
  56. int GCommCheck( int Key )
  57. {
  58.     register int i;
  59.  
  60.     for (i=0; i<MAXKEYS; ++i)
  61.         if ( Key == GCommKey[i].Key )
  62.             return(1);
  63.     return( 0 );
  64. }
  65.  
  66. int GComm()
  67. {
  68.     register int i, key, rtn;
  69.  
  70. GetAnotherKey:
  71.  
  72.     while ( bioskey(1) == 0 )
  73.         if ( GCommBackgroundFunc != NULL )
  74.             GCommBackgroundFunc();
  75.  
  76.     key = bioskey(0);
  77.  
  78.     if ( key & 0x00ff )
  79.         rtn = key & 0x00ff;
  80.     else
  81.         rtn = ( ( key & 0xff00 ) >> 8 ) | 256;
  82.  
  83.     for (i=0; i<MAXKEYS; ++i)
  84.         if ( rtn == GCommKey[i].Key ) {
  85.             GCommKey[i].Func();
  86.             goto GetAnotherKey;
  87.         }
  88.  
  89.     return( rtn );
  90. }
  91.